<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'righttree.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.5/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.5/themes/default/easyui.css">
    <script type="text/javascript" src="js/jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/jquery-easyui-1.4.5/locale/easyui-lang-zh_CN.js"></script>
	
  	<script type="text/javascript">
  	var selnode;
  		 $(function(){
  		 
         $('#tt').tree({
                 url:"right/list.action?checked="+false,
                 method:'post',
            onBeforeLoad: function(node){
alert(node);
                if(node != null){
                    if(node.checked){                        
                         $('#tt').tree('options').url = "${pageContext.request.contextPath}/shebei/getTree.action?checked="+true;
                    }else{
                        $('#tt').tree('options').url = "${pageContext.request.contextPath}/shebei/getTree.action?checked="+false;          
                    }
                }else{
                    $('#tt').tree('options').url = "${pageContext.request.contextPath}/shebei/getTree.action?checked="+false;
                };
            }
        });
  });

  			
  			//点提交添加权限按钮的时候窗口关闭并将表单序列化传参
  			$("#but").click(function(){
  			//关闭弹出框
  			$("#window").window("close");
  				
  				var noteid=$("#ttx").tree("getChecked",['checked','indeterminate']);
 				var ids="";
 				alert(noteid.length);
 				for(var i=0;i<noteid.length;i++){
 					if(ids==""){
 						ids=ids+noteid[i].ri_id;
 					}
 					else{
 						ids=ids+",";
 						ids=ids+noteid[i].ri_id;
 					}
 				}
 				alert(ids);
 				$("#id").val(ids);
 				alert($("#form").serialize());
 				var str=$("#form").serialize();
 				//异步交互
  				$.get("role/addRoleRight.action",str,function(res){
  					if(res=="ok"){
  						$("#tt").tree("reload");
  					}
  				})
  			});
  		});
  		//点击删除
  		function del(){
  			if(confirm("你确定要删除这个权限吗？")){
  				$.post("","id="+selnode.ri_id,function(res){
  				//alert(res);
  					if(res=='ok'){
  						$("#tt").tree("reload");
  					}
  				});
  			}
  		}
  	/*弹出窗口  */
  		function add(){
  			$("#window").window("open");
  		}
  	</script>
  </head>
  
  <body>
  <!-- 展示树 -->
  <h5>角色名：${rr.ro_name} <span><a href="javascript:add()">添加权限</a></span></h5>
  <h6>角色的权限：</h6>
    <ul id="tt" class="easyui-tree" data-options="url:'role/getRightByrid.action?id=${rr.ro_id}'"></ul>
    <!-- 点击右键菜单 -->
    <div class="easyui-menu" id="mm">
    	<div onclick="del()">删除权限</div>
    </div>
    
    <div id="window" class="easyui-window" data-options="modal:true,closed:true" width=400px;>
    <h3>增加权限</h3>
    <form id="form">
    	 <ul id="ttx" class="easyui-tree" data-options="url:'right/list.action',checkbox:true"></ul>
    	 <input type="hidden" name="ids" id="id"/>
    	 <input type="hidden" name="ro_id" value="${rr.ro_id}"/>
    	 <input type="button" id="but" value="提交">
    </form>
    </div>
  </body>
</html>
